package com.ruoyi.system.netty;

import cn.hutool.core.util.HexUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

public class MessagePacketDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
        int length = buffer.readableBytes();
        System.out.println("长度："+length);
        byte[] bytesReady = new byte[buffer.readableBytes()];
        buffer.writeBytes(bytesReady);
        String s = HexUtil.encodeHexStr(bytesReady);
        //这之间可以进行报文的解析处理
        out.add(s);
    }
}
